﻿Imports System.Windows.Forms.VisualStyles

Public Class FillForm
    Public Shared Sub FillFormboxes(ByVal detailsin As List(Of String), ByVal type As String, ByVal RDP As Boolean)
        If type = "comp" Then
            NewUi.dgseamulticomp.Rows.Clear()
            Dim uname As String = Nothing
            ' ReSharper disable RedundantAssignment
            Dim pcname As String = Nothing
            Dim serial As String = Nothing
            Dim resid As String = Nothing
            Dim consolemin As String = Nothing
            Dim consolecount As String = Nothing
            ' ReSharper restore RedundantAssignment
            Dim compnames = New List(Of String)
            If detailsin.Count = 1 Then
                If RDP Then
                    Shell(Environment.GetEnvironmentVariable("systemroot").ToString() & "\system32\mstsc.exe /v:" & Split(detailsin(0), "|")(1).ToString())
                    NewUi.Close()
                Else
                    NewUi.Sinfillform(detailsin)
                End If
            Else
                For Each client In detailsin
                    Dim clientinfo As Object = Split(client.ToString, "|")
                    'define vars
                    uname = clientinfo(0).ToString
                    pcname = clientinfo(1).ToString
                    serial = clientinfo(2).ToString
                    consolemin = clientinfo(3).ToString
                    consolecount = clientinfo(4).ToString
                    resid = clientinfo(5).ToString
                    'fill datagrid
                    If compnames.Count > 0 Then
                        Dim comcount As Integer = 0
                        ' ReSharper disable LoopCanBeConvertedToQuery
                        For Each Comp In compnames
                            ' ReSharper restore LoopCanBeConvertedToQuery
                            If Comp = pcname Then
                                comcount = comcount + 1
                            End If
                        Next
                        If comcount = 0 Then
                            NewUi.dgseamulticomp.Rows.Add(New String() {pcname, uname, serial, consolecount, consolemin, resid})
                        End If
                    Else
                        NewUi.dgseamulticomp.Rows.Add(New String() {pcname, uname, serial, consolecount, consolemin, resid})
                    End If
                    compnames.Add(pcname)
                    'clear vars
                    ' ReSharper disable once RedundantAssignment
                    pcname = Nothing
                    ' ReSharper disable once RedundantAssignment
                    serial = Nothing
                Next
                NewUi.pansea.Visible = False
                NewUi.panseamulticomp.Visible = True
                NewUi.panseamulticomp.Location = New Point(3, 3)
                NewUi.dgseamulticomp.AutoResizeColumns()
                NewUi.panseamultiuser.Visible = False
                NewUi.dgseamulticomp.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
                NewUi.tslbl.Text = "Multiple computer result for " & uname
            End If
        ElseIf type = "user" Then
            NewUi.dgseamultiuser.Rows.Clear()
            Dim uname As String
            Dim dom As String
            For Each user In detailsin
                Dim userinfo As Object = Split(user.ToString, "\")
                dom = userinfo(0).ToString
                uname = UCase(userinfo(1).ToString)
                NewUi.dgseamultiuser.Rows.Add(New String() {dom, uname})
            Next
            NewUi.pansea.Visible = False
            NewUi.panseamultiuser.Visible = True
            NewUi.panseamultiuser.Location = New Point(3, 3)
            NewUi.dgseamultiuser.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            NewUi.dgseamultiuser.AutoResizeColumns()
            NewUi.tslbl.Text = "Multiple users found please select"
        End If
    End Sub
End Class
